<?php

class Mylab_Model
{
  protected $_row;
  protected $_dbTable;

  public function __construct(Zend_Db_Table_Abstract $dbTable, $id = null) {

    $this->_dbTable = $dbTable;
    if ($id) {
      $this->_row = $this->_dbTable->find($id)->current();
    } else {
      $this->_row = $this->_dbTable->createRow();
    }
  }

  public function fill($data) {
    foreach ($data as $key => $value) {
      if(isset($this->_row->$key)){
        $this->_row->$key = $value;
      }
    }
  }

  public function save() {
      $this->_row->modified_date = date('Y-m-d H:i:s');
    return $this->_row->save();
  }

  public function delete() {
    $this->_row->delete();
  }

  public function __set($name, $value) {
    if(isset($this->_row->$name)){
      $this->_row->$name = $value;
    }
  }

  public function __get($name) {
    if(isset($this->_row->$name)){
      return $this->_row->$name;
    }
  }
}
